package Chapter8;
import java.io.*;
public class Example19 {
	public static void main(String[] args) throws Exception{
		final PipedInputStream pis=new PipedInputStream();
		final PipedOutputStream pos=new PipedOutputStream();
		pis.connect(pos);
		new Thread(new Runnable() {
			public void run() {
				BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
				PrintStream ps=new PrintStream(pos);
				while(true) {
					try {
						System.out.println(Thread.currentThread().getName()+"request typing in :");
						ps.println(br.readLine());
						Thread.sleep(1000);
					}catch(Exception e) {
						e.printStackTrace();
					}
				}
			}
		},"be sent Thread").start();
		new Thread(new Runnable() {
			public void run() {
				BufferedReader br=new BufferedReader(new InputStreamReader(pis));
				PrintStream ps=new PrintStream(pos);
				while(true) {
					try {
						System.out.println(Thread.currentThread().getName()+"getting data "+br.readLine());
						ps.println(br.readLine());
						Thread.sleep(1000);
					}catch(Exception e) {
						e.printStackTrace();
					}
				}
			}
		},"getting thread").start();
	}

}
